﻿#region Imports
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Forms;
using CommonUtilities.Attributes;
using CommonUtilities.Controls;
using CommonUtilities.Extensions;
using CommonUtilities.UITest.Models;
#endregion

namespace CommonUtilities.UITest
{
    public partial class frmDataGridView : Form
    {
        public frmDataGridView()
        {
            InitializeComponent();
        }

        private void frmDataGridView_Load(object sender, EventArgs e)
        {
            //foreach (DataGridViewColumn dcol in dgvTest.GenerateDGVColumns<Test_Entity>(true))
            //    dgvTest.Columns.Add(dcol);
            //dgvTest = (CUtil_DataGridView)
            dgvTest.GenerateDGVColumns<Test_Entity>(true);

            ObservableCollection<Test_Entity> data = new ObservableCollection<Test_Entity>();
            data.Add(new Test_Entity(@"C:\"));
            data.Add(new Test_Entity(@"Z:\"));

            dgvTest.DataSource = data.ToObservableCollection();
            dgvCopy.DataSource = data.ToObservableCollection();
        }
    }
}

namespace CommonUtilities.UITest.Models
{
    [Description("Description_test")]
    [DisplayName("DisplayName_test")]
    public class Test_Entity
    {
        #region Declarations
        private long byteSize;
        #endregion

        #region Constructors
        public Test_Entity()
        {

        }

        public Test_Entity(string dirName)
        {
            DirName = dirName;
        }
        #endregion

        #region Properties
        [Unique]
        [DisplayName("Dir. name")]
        public string DirName { get; private set; }
        [Browsable(false)]
        [DisplayName("Full path")]
        public string DirPath { get; private set; }
        [Browsable(false)]
        [DisplayName("Relative path")]
        public string RelPath { get; private set; }
        [DisplayName("Size (bytes)")]
        public long ByteSize { get { return byteSize; } private set { byteSize = value; } }
        [DisplayName("Directory size")]
        public string DirSize { get { return ByteSize.ToPracticalSize(); } }
        [Browsable(false)]
        [DisplayName("#")]
        public long Sort { get; set; }
        [DisplayName("# files")]
        public long FileCount { get; private set; }
        [Browsable(false)]
        [DisplayName("Avg. size (bytes)")]
        public long AvgByteSize { get { return FileCount == 0 ? 0 : ByteSize / FileCount; } }
        [DisplayName("Avg. size per file (B)")]
        public string AvgFileSize { get { return AvgByteSize.ToPracticalSize(); } }
        [DisplayName("Last modified")]
        public string LastModified { get; private set; }
        #endregion
    }
}